#include<iostream>
using namespace std;
typedef long long ll;
ll dfs(ll n)
{
	if(n==1||n==2)return 0;
    if(n&1)return dfs(n/2)+dfs(n/2+1)+1;//如果是奇数,那么就会相差1
    else return dfs(n/2)*2;
}
int main()
{
	int t;
    cin>>t;
    while(t--)
    {
    	ll n;
        cin>>n;
        cout<<dfs(n)<<endl;
    }
    return 0;
}
